www.gusucode.com > VC++ 特殊网址访问器源代码-源码程序 > VC++ 特殊网址访问器源代码-源码程序/code/Demo3/UrlSetDlg.cpp

    //Download by http://www.NewXing.com
// UrlSetDlg.cpp : implementation file
//

#include "stdafx.h"
#include "Demo03.h"
#include "UrlSetDlg.h"

//增加网址表的DaoRecordSet的引用声明
#include "DomainDaoSet.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CUrlSetDlg dialog


CUrlSetDlg::CUrlSetDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CUrlSetDlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CUrlSetDlg)
	m_strUrl = _T("");
	//}}AFX_DATA_INIT
}


void CUrlSetDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CUrlSetDlg)
	DDX_Text(pDX, IDC_EDIT_URL, m_strUrl);
	DDV_MaxChars(pDX, m_strUrl, 50);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CUrlSetDlg, CDialog)
	//{{AFX_MSG_MAP(CUrlSetDlg)
	ON_BN_CLICKED(ID_URL_ADD, OnUrlAdd)
	ON_BN_CLICKED(ID_URL_DEL, OnUrlDel)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CUrlSetDlg message handlers

void CUrlSetDlg::OnUrlAdd() 
{
	// TODO: Add your control notification handler code here
	//同步变量和控件内容
	UpdateData(TRUE);

	CDomainDaoSet m_DomainDaoSet;
	CString		  m_strSql;
	try
	{
		if(m_DomainDaoSet.IsOpen())
			m_DomainDaoSet.Close();
		
		//标准的SQL语句
		m_strSql.Format("select * from pDomain where DomainName = '%s'",m_strUrl.operator LPCTSTR());
		m_DomainDaoSet.Open(AFX_DAO_USE_DEFAULT_TYPE,m_strSql,0);
		//如果网址库已经存在,则不添加
		if(!m_DomainDaoSet.IsEOF())
		{
			AfxMessageBox("网址已经存在,不用再添加了!");
			return;
		}
		//增加新记录
		m_DomainDaoSet.AddNew();
		//记录设置
		m_DomainDaoSet.m_DomainName = m_strUrl;
		m_DomainDaoSet.m_DomainType = 1;	//1 用户添加

		//更新记录到数据库中
		if(m_DomainDaoSet.CanUpdate())
		{
			m_DomainDaoSet.Update();			
		}
		//关闭记录集
		if(m_DomainDaoSet.IsOpen())
			m_DomainDaoSet.Close();
	}
	//意外捕获
	catch(CDaoException*e)
	{
		e->ReportError ();
		//e->Delete ();
		return;
	}	
	AfxMessageBox("网址添加成功!");
	//将控件中的输入内容清除,以便再次输入其他记录
	m_strUrl = _T("");
	//将变量内容更新到控件中,注意参数
	UpdateData(FALSE);
}

void CUrlSetDlg::OnUrlDel() 
{
	// TODO: Add your control notification handler code here
	UpdateData(TRUE);

	CDomainDaoSet m_DomainDaoSet;
	CString		  m_strSql;
	try
	{
		if(m_DomainDaoSet.IsOpen())
			m_DomainDaoSet.Close();
		
		//标准的SQL语句
		m_strSql.Format("select * from pDomain where DomainName = '%s'",m_strUrl.operator LPCTSTR());
		m_DomainDaoSet.Open(AFX_DAO_USE_DEFAULT_TYPE,m_strSql,0);
		//如果网址库已经存在,则不添加
		if(m_DomainDaoSet.IsEOF())
		{
			AfxMessageBox("网址已经不在数据库中,不需要删除!");
			return;
		}
		//增加新记录
		m_DomainDaoSet.Delete();
		//关闭记录集
		if(m_DomainDaoSet.IsOpen())
			m_DomainDaoSet.Close();
	}
	//意外捕获
	catch(CDaoException*e)
	{
		e->ReportError ();
		//e->Delete ();
		return;
	}	
	AfxMessageBox("网址删除成功!");
	//将控件中的输入内容清除,以便再次输入其他记录
	m_strUrl = _T("");
	//将变量内容更新到控件中,注意参数
	UpdateData(FALSE);	
}